package cn.iocoder.yudao.module.erp.dal.mysql.purchaseplan.purchaseequipmentdetail;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.purchaseplan.vo.purchaseequipmentdetail.PurchaseEquipmentDetailPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.purchaseplan.purchaseequipmentdetail.PurchaseEquipmentDetailDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 设备采购计划明细 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface PurchaseEquipmentDetailMapper extends BaseMapperX<PurchaseEquipmentDetailDO> {

    default PageResult<PurchaseEquipmentDetailDO> selectPage(PurchaseEquipmentDetailPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PurchaseEquipmentDetailDO>()
                .eqIfPresent(PurchaseEquipmentDetailDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(PurchaseEquipmentDetailDO::getPurchaseType, reqVO.getPurchaseType())
                .eqIfPresent(PurchaseEquipmentDetailDO::getCategory, reqVO.getCategory())
                .likeIfPresent(PurchaseEquipmentDetailDO::getEquipmentName, reqVO.getEquipmentName())
                .eqIfPresent(PurchaseEquipmentDetailDO::getUnit, reqVO.getUnit())
                .eqIfPresent(PurchaseEquipmentDetailDO::getParameterRequirements, reqVO.getParameterRequirements())
                .eqIfPresent(PurchaseEquipmentDetailDO::getSupplierQualification, reqVO.getSupplierQualification())
                .eqIfPresent(PurchaseEquipmentDetailDO::getReviewRequirements, reqVO.getReviewRequirements())
                .eqIfPresent(PurchaseEquipmentDetailDO::getEstimatedQuantity, reqVO.getEstimatedQuantity())
                .eqIfPresent(PurchaseEquipmentDetailDO::getEstimatedUnitPrice, reqVO.getEstimatedUnitPrice())
                .eqIfPresent(PurchaseEquipmentDetailDO::getTotalAmount, reqVO.getTotalAmount())
                .eqIfPresent(PurchaseEquipmentDetailDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(PurchaseEquipmentDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PurchaseEquipmentDetailDO::getId));
    }

    default void deleteByPlanId(Long planId){
        LambdaUpdateWrapper<PurchaseEquipmentDetailDO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(PurchaseEquipmentDetailDO::getPlanId, planId);
        this.delete(updateWrapper);
    }

    default List<PurchaseEquipmentDetailDO> selectByPlanId(Long planId){
        LambdaQueryWrapper<PurchaseEquipmentDetailDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PurchaseEquipmentDetailDO::getPlanId, planId)
                .eq(PurchaseEquipmentDetailDO::getDeleted,0);
        return this.selectList(queryWrapper);
    }
}